//
//  MapBaiduViewController.m
//  SXH
//
//  Created by 房 国生 on 15/8/6.
//  Copyright (c) 2015年 lyss. All rights reserved.
//
typedef void(^isSelectedBlock)(BOOL isYES);
#import "MapBaiduViewController.h"
#import "CommonService.h"
#import "SpotEntity.h"
#import "AppDelegate.h"
#import "MBProgressHUD.h"
#import "YYAnimationIndicator.h"
#import "SpotDetailViewController.h"
#import "BasicMapAnnotation.h"
#import "MapDXAlertView.h"
#import "DBManager.h"
#import "UIImage+Rotate.h"
#import "LocationManagement.h"
#import "RouteAnnotation.h"
#import "RoadLineEntity.h"
#import "SpotDetailViewController.h"
#import "AFSoundManager.h"
#import "UIImageView+WebCache.h"
#import "GXScrollView.h"
#import "UIView+AutoLayout.h"
#import "GXScrollEntity.h"
#import "JDStatusBarNotification.h"
#import "SVProgressHUD.h"
#import "AroundHotelViewController.h"
#import "MapRouteViewController.h"
#import "GXPlayView.h"
#import "ShareChooseViewController.h"
#import "LoginViewController.h"
typedef enum : NSUInteger {
    TrailStart,
    TrailEnd
} Trail;
typedef NS_ENUM(NSUInteger,AutoPlayType) {
    AutoPlayTypeYes,
    AutoPlayTypeNo
};
static SpotEntity * musicSpotEntity;
static BOOL isPlay = NO;
static BOOL reStart = NO;
static BOOL isCircle = NO;
static AutoPlayType autoPlayType = AutoPlayTypeNo;
static NSMutableArray * sameArray;
static NSMutableArray *musicArrayList;
@interface MapBaiduViewController ()<UITextFieldDelegate, BMKRouteSearchDelegate,LocationManagementDelegate,AFSoundManagerDelegate,GXScrollViewDelegate> {
    YYAnimationIndicator *indicator;
    int zoom;
    int textFieldPop;
    BMKRouteSearch* _routesearch;
    BOOL autoStart;
    BOOL isPause;
    BOOL oneTime;
    BOOL locationOnce;//decide first time user's location
//    NSString *decType;
    NSString *spot_path;
    NSMutableArray * moreArray;
    GXScrollView * scroll;
   
}


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height5;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height4;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height1;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height2;
@property (weak, nonatomic) IBOutlet UIImageView *imageCut;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *height3;

@property (weak, nonatomic) IBOutlet UIView *viewPop;
@property (nonatomic, strong) IBOutlet UIButton *btnSpot;
@property (nonatomic, strong) IBOutlet UIButton *btnSpotText;
@property (nonatomic, strong) IBOutlet UIButton *btnBusiness;
@property (nonatomic, strong) IBOutlet UIButton *btnBusinessText;
@property (nonatomic, strong) IBOutlet UIButton *btnToilet;
@property (nonatomic, strong) IBOutlet UIButton *btnToiletText;
@property (nonatomic, strong) IBOutlet UIButton *btnOther;
@property (nonatomic, strong) IBOutlet UIButton *btnOtherText;
@property (nonatomic, strong) IBOutlet UIButton *btnRoute;
@property (nonatomic, strong) IBOutlet UIButton *btnRouteText;

@property (nonatomic, strong) IBOutlet UITextField *textFieldStart;
@property (nonatomic, strong) IBOutlet UITextField *textFieldEnd;

@property (nonatomic, strong) IBOutlet UIView *viewPopMenu;
@property (nonatomic, strong) IBOutlet UIPickerView *pickerView;

@property (nonatomic, strong) BasicMapAnnotation *spotEntityStart;
@property (nonatomic, strong) BasicMapAnnotation *spotEntityEnd;

@property (nonatomic, strong) RoadLineEntity *mRoadLineEntity;
@property (nonatomic, strong) SpotEntity *userSpotEntity;


@property (weak, nonatomic) IBOutlet UIButton *btnCancleAuto;
@property (weak, nonatomic) IBOutlet UIButton *btnSmall;
@property (weak, nonatomic) IBOutlet UIButton *btnLocation;
@property (weak, nonatomic) IBOutlet UIView *viewTogether;
@property (weak, nonatomic) IBOutlet UIButton *btnBig;

@property (nonatomic, strong) NSMutableArray *arrayMusicNumber;
@property (weak, nonatomic) IBOutlet UIView *labelLine;

@property (nonatomic,strong)NSTimer *myTimer;

@property (nonatomic,strong)BMKUserLocation *autoLocation;
//@property (nonatomic,strong) SpotEntity * musicSpotEntity;
@property (nonatomic,strong) GXScrollView *businessScroll;
@property (nonatomic,strong) NSMutableArray *arrayBusinessMore;
@property (strong, nonatomic) IBOutlet UIImageView *popView;
@property (weak, nonatomic) IBOutlet UIImageView *popViewAngel;
@property (nonatomic, strong) UIView *businessView;
@property (nonatomic, strong) SpotEntity *playMusicEntity;
@property (strong, nonatomic) IBOutlet UIView *viewExplain;
@property (weak, nonatomic) IBOutlet UITextView *textViewContent;
@property (nonatomic,strong)isSelectedBlock block;
@property (nonatomic) float currentZoomLevel;

/** 位置数组 */
@property (nonatomic, strong) NSMutableArray *locationArrayM;

/** 轨迹记录状态 */
@property (nonatomic, assign) Trail trail;

/** 起点大头针 */
@property (nonatomic, strong) BMKPointAnnotation *startPoint;

/** 终点大头针 */
@property (nonatomic, strong) BMKPointAnnotation *endPoint;

/** 轨迹线 */
@property (nonatomic, strong) BMKPolyline *polyLine;

@property (nonatomic, strong) GXPlayView *playView;
@end
static NSString *const SBStyle2 = @"SBStyle2";

@implementation MapBaiduViewController
@synthesize mutableArraySpot;
@synthesize btnBusiness, btnBusinessText, btnOther, btnOtherText;
@synthesize btnRoute, btnRouteText, btnSpot, btnSpotText, btnToilet;
@synthesize btnToiletText, viewPopMenu, pickerView;
@synthesize parkEntity, spotEntityStart, spotEntityEnd, userSpotEntity;
@synthesize mutableArray, mutableArrayRoad;
@synthesize btnCancleAuto,btnSmall,btnLocation,btnBig,viewTogether;
/** 点击景点后的数组 */

-(SpotEntity *)playMusicEntity
{
    if (!_playMusicEntity) {
        _playMusicEntity = [[SpotEntity alloc] init];
    }
    return _playMusicEntity;
}

-(UIView *)businessView
{
    if (!_businessView) {
        _businessView = [[UIView alloc]initWithFrame:CGRectZero];
    }
    return _businessView;
}

-(GXScrollView *)businessScroll
{
    if (!_businessScroll) {
        
        _businessScroll = [[GXScrollView alloc] initWithEntityArray:_arrayBusinessMore];
        _businessScroll.tag = 2000;
        _businessScroll.gxDelegate = self;
 
    }
    return _businessScroll;
}
- (NSString*)getMyBundlePath1:(NSString *)filename
{
    
    NSBundle * libBundle = MYBUNDLE ;
    if ( libBundle && filename ){
        NSString * s=[[libBundle resourcePath ] stringByAppendingPathComponent : filename];
        return s;
    }
    return nil ;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    musicArrayList = _mutableArrayMusic;
    _playView = [GXPlayView sharedInstance];
    [JDStatusBarNotification addStyleNamed:SBStyle2
                                   prepare:^JDStatusBarStyle *(JDStatusBarStyle *style) {
                                       style.barColor = [UIColor colorWithRed:0.365 green:0.800 blue:0.271 alpha:1.00];
                                       style.textColor = [UIColor whiteColor];
                                       style.animationType = JDStatusBarAnimationTypeBounce;
                                       if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
                                           style.font = [UIFont fontWithName:@"DINCondensed-Bold" size:15.0];
                                           style.textVerticalPositionAdjustment = 2.0;
                                           
                                       } else {
                                           style.font = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:15.0];
                                       }
                                       return style;
                                   }];

    locationOnce = YES;
    self.title = @"地图";
    mutableArraySpot = [[NSMutableArray alloc] init];
    self.fd_interactivePopDisabled = YES;
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
//        ALERT_ERR_MSG(@"使用地图功能需打开定位服务");
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"使用地图功能需打开定位服务" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
        [alert show];
        alert.tag = 10001;
    }

    _locService = [[BMKLocationService alloc]init];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    _locService.delegate = self;
    zoom = 16;
    [_mapView setZoomLevel:zoom+0.3];
    _currentZoomLevel = _mapView.zoomLevel;
    _routesearch = [[BMKRouteSearch alloc]init];
    
    //    [[LocationManagement sharedInstance] startGPS];
    //    [LocationManagement sharedInstance].delegate = self;
    
    
    [_locService startUserLocationService];
    //增加当前位置
    userSpotEntity = [[SpotEntity alloc] init];
    userSpotEntity.title = @"我的位置";
    userSpotEntity.ptype = @"5";
    userSpotEntity.latitude = [NSString stringWithFormat:@"%f", [LocationManagement sharedInstance].location.coordinate.latitude];
    userSpotEntity.longitude = [NSString stringWithFormat:@"%f", [LocationManagement sharedInstance].location.coordinate.longitude];
    [self setAnnotionsWithList:@"1"];
    
    [self.viewPopMenu setFrame:CGRectMake(0, ScreenHeight,ScreenWidth, viewPopMenu.frame.size.height)];
    [self.view addSubview:self.viewPopMenu];
    
    self.textFieldStart.delegate = self;
    self.textFieldEnd.delegate = self;
    
    CLLocation *location = [[CLLocation alloc] initWithLatitude:[parkEntity.latitude doubleValue]
                                                      longitude:[parkEntity.longitude doubleValue]];
    [_mapView setCenterCoordinate:location.coordinate animated:YES];
    autoStart = NO;
    oneTime = YES;
    _arrayMusicNumber = [[NSMutableArray alloc] init];
    isPause = YES;
    _autoLocation = [[BMKUserLocation alloc]init];
    moreArray = [[NSMutableArray alloc] init];
    _arrayBusinessMore = [[NSMutableArray alloc] init];
    
    [self performSelector:@selector(doDataCaculation) withObject:nil afterDelay:0.0];
    
    
    
    if ([[SpotDetailViewController sharedInstance].parkEntity.ID isEqualToString:parkEntity.ID]) {
        if ([SpotDetailViewController sharedInstance].isPlay) {
            
            [self.view addSubview:_playView];
            musicSpotEntity = [SpotDetailViewController sharedInstance].currentSpot;
            _playView.parkEntity = parkEntity;
            _playView.entity = musicSpotEntity;
            
            __weak __typeof(self)weakSelf  = self;
            [[SpotDetailViewController sharedInstance] playMusicProgress:^(double progress) {
                _playView.progressSlider.progress = progress;
            } finshBlock:^{
                _playView.progressSlider.progress = 0;
                DebugLog(@"===========%f",_playView.progressSlider.progress);
                reStart = YES;
                _playView.btnPlay.hidden = NO;
                _playView.btnStop.hidden = YES;
                if (autoPlayType == AutoPlayTypeYes) {
                    if (oneTime) {
                        [_arrayMusicNumber removeAllObjects];
                        autoStart = YES;
                        isCircle = YES;
                        [weakSelf didUpdateBMKUserLocation:_autoLocation];
                    }
                }
            }nextBlock:^(SpotEntity *entity){
                musicSpotEntity = entity;
                _playView.entity = entity;
                _playView.btnPlay.hidden = YES;
                _playView.btnStop.hidden = NO;
            }];
            
            _playView.frame = CGRectMake(8, SCREEN_HEIGHT - (SCREEN_WIDTH - 16)*117/362-5, SCREEN_WIDTH -16, (SCREEN_WIDTH - 16)*117/362);
            for (int i = 0; i<[_mapView.annotations count]; i++) {
                if ([[_mapView.annotations objectAtIndex:i] isKindOfClass:[BasicMapAnnotation class]]) {
                    BasicMapAnnotation *annotation = [_mapView.annotations objectAtIndex:i];
                    BMKAnnotationView *anView=  [_mapView viewForAnnotation:[_mapView.annotations objectAtIndex:i]];
                    anView.image = [UIImage imageNamed:@"地图图标_景点"];
                    [anView setSelected:NO animated:YES];
                    if ([musicSpotEntity.title isEqualToString:annotation.title]) {
                        
                        [anView setSelected:YES animated:YES];
                        anView.image = [UIImage imageNamed:@"自动语音播报"];
                    }
                }
            }
            _height3.constant = _playView.bounds.size.height-40 ;
            
        }
        
    }
    if(autoPlayType == AutoPlayTypeYes){
        autoStart = YES;
        [btnCancleAuto setBackgroundImage:[UIImage imageNamed:@"取消auto讲解.png"] forState:UIControlStateNormal];
    }  
    /**
     *  判断退出进来时的状态
     */
    [[SpotDetailViewController sharedInstance] pauseImage:^{
        _playView.btnPlay.hidden = NO;
        _playView.btnStop.hidden = YES;
    } resume:^{
        _playView.btnPlay.hidden = YES;
        _playView.btnStop.hidden = NO;
    }];
        /**
     *  控件功能BLOCK
     */
    [_playView doStopActionWithBlock:^{
        _playView.btnStop.hidden = YES;
        _playView.btnPlay.hidden = NO;
        isPause = YES;
        [self pauseAudio];
    } doPlayActionWithBlock:^{
        _playView.btnStop.hidden = NO;
        _playView.btnPlay.hidden = YES;
        isPause = NO;
        if ([SpotDetailViewController sharedInstance].reStart) {
            [self restartAudio];
        }else{
            [self resumeAudio];
        }
        
    } doNavigationActionWithBlock:^{
        spotEntityStart = [[BasicMapAnnotation alloc] init];
        spotEntityStart.latitude = _autoLocation.location.coordinate.latitude;
        spotEntityStart.longitude = _autoLocation.location.coordinate.longitude;
        spotEntityStart.title = @"当前位置";
        spotEntityEnd = [[BasicMapAnnotation alloc] init];
        
            spotEntityEnd.latitude = [musicSpotEntity.latitude doubleValue];
            spotEntityEnd.longitude = [musicSpotEntity.longitude doubleValue];
            spotEntityEnd.title = musicSpotEntity.title;
      
        [self walkRoute];
    } doCloseWithBlock:^{
      
        [sameArray removeAllObjects];
        
        if (autoPlayType == AutoPlayTypeYes||autoStart==NO) {
            isCircle = NO;
            [btnCancleAuto setBackgroundImage:[UIImage imageNamed:@"auto讲解.png"] forState:UIControlStateNormal];
            autoPlayType = AutoPlayTypeNo;
            [SpotDetailViewController sharedInstance].autoPlayFunction = NO;
        }
        [self pauseAudio];
        [self hideLocationUp];
        autoStart = NO;
    } doContentPlayActionWithBlock:^{
        _viewExplain.hidden = NO;
        if (![_mapView.subviews containsObject:self.viewExplain]) {
            [_mapView addSubview:self.viewExplain];
            [self.viewExplain mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.equalTo(@(_playView.bounds.size.width -2));
                make.height.equalTo(@(_playView.bounds.size.height-2));
                make.left.equalTo(_playView.mas_left).offset(1);
                make.bottom.equalTo(_playView.mas_bottom).offset(1);
            }];
        }
        [UIView animateWithDuration:0.5 //速度0.7秒
                         animations:^{//修改坐标
                             _viewExplain.layer.transform = CATransform3DMakeTranslation(0, -(_playView.bounds.size.height-2), 0);
                             btnLocation.layer.transform = CATransform3DMakeTranslation(0, -(_playView.bounds.size.height- 10), 0);
                             btnSmall.layer.transform = CATransform3DMakeTranslation(0, -(_playView.bounds.size.height- 10), 0);
                             btnBig.layer.transform = CATransform3DMakeTranslation(0, -(_playView.bounds.size.height- 10), 0);
                             btnCancleAuto.layer.transform = CATransform3DMakeTranslation(0, -(_playView.bounds.size.height- 10), 0);
                             //                         _mapView.layer.transform =  CATransform3DMakeTranslation(0, -(viewAutoPlay.bounds.size.height- 2), 0);
                             
                         }completion:^(BOOL finished) {
                             [_mapView setMapCenterToScreenPt:CGPointMake(self.view.center.x, self.view.center.y -(_playView.bounds.size.height- 2) )];
                         }];

    }];
    _textViewContent.layoutManager.allowsNonContiguousLayout = NO;
    _textViewContent.text = musicSpotEntity.content;
}

- (IBAction)viewExplainClose:(id)sender {
    [UIView animateWithDuration:0.3 animations:^{
        _viewExplain.layer.transform = CATransform3DIdentity;
//         _mapView.layer.transform = CATransform3DIdentity;
        
        btnLocation.layer.transform = CATransform3DIdentity;
        btnSmall.layer.transform =CATransform3DIdentity;
        btnBig.layer.transform = CATransform3DIdentity;
        btnCancleAuto.layer.transform = CATransform3DIdentity;

    }completion:^(BOOL finished) {
        [_mapView setMapCenterToScreenPt:CGPointMake(self.view.center.x, self.view.center.y )];
    } ];
   
}
-(void)createPath
{
    NSString *document = [NSString stringWithFormat:@"%@/Library/Caches",NSHomeDirectory()];
    NSString *folder = [document stringByAppendingPathComponent:@"lyss"];
    NSString *fileNameTemp = [NSString stringWithFormat:@"park_%@",parkEntity.ID];
    NSString *park_path = [folder stringByAppendingPathComponent:fileNameTemp];
    spot_path = [park_path stringByAppendingPathComponent:@"audio"];
}

-(void)createView
{
    
    CGFloat top = 0; // 顶端盖高度
    CGFloat bottom = 0 ; // 底端盖高度
    CGFloat left = 30; // 左端盖宽度
    CGFloat right = 10; // 右端盖宽度
    UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
    // 指定为拉伸模式，伸缩后重新赋值
   
    
    [_mapView addSubview:self.businessView];
    [_businessView addSubview:_popView];
    [_businessView addSubview:self.businessScroll];
    
         _popView.image = [_popView.image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    if ([_arrayBusinessMore count] == 1) {
        [_popView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(_businessScroll.bounds.size.width + 8));
            make.height.equalTo(@(42));
            make.bottom.equalTo(viewTogether.mas_top).offset(-13);
            make.left.equalTo(btnLocation.mas_right).offset(39);
        }];

        [self.businessView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(_businessScroll.bounds.size.width + 8));
            make.height.equalTo(@(52));
            make.bottom.equalTo(viewTogether.mas_top).offset(-3);
            make.left.equalTo(btnLocation.mas_right).offset(39);
        }];
    }else{
        [_popView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(_businessScroll.bounds.size.width + 8));
            make.height.equalTo(@(42));
            make.bottom.equalTo(viewTogether.mas_top).offset(-13);
            make.left.equalTo(btnLocation.mas_right).offset(-2);
        }];

        [self.businessView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(_businessScroll.bounds.size.width + 8));
            make.height.equalTo(@(52));
            make.bottom.equalTo(viewTogether.mas_top).offset(-3);
            make.left.equalTo(btnLocation.mas_right).offset(-2);
        }];
    }
   
    [_businessView addSubview:_popViewAngel];
    [_popViewAngel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(26));
        make.height.equalTo(@(13));
        make.top.equalTo(_imageCut.mas_bottom).offset(-15);
        make.left.equalTo(btnLocation.mas_right).offset(52);
    }];
    _businessView.hidden = YES;
}
-(void)doDataCaculation{
    
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:4]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"推荐路线";
        entity.type = @"4";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:5]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"医务室";
        entity.type = @"5";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:6]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"出入口";
        entity.type = @"6";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:7]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"休息区";
        entity.type = @"7";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:8]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"停车场";
        entity.type = @"8";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:9]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"售票处";
        entity.type = @"9";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:10]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"游船登陆点";
        entity.type = @"10";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:11]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"电瓶车乘车点";
        entity.type = @"11";
        [moreArray addObject:entity];
    }
    if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:12]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"餐饮服务点";
        entity.type = @"12";
        [moreArray addObject:entity];
    }if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:13]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"游览车站";
        entity.type = @"13";
        [moreArray addObject:entity];
        
    }if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:14]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"警卫处";
        entity.type = @"14";
        [moreArray addObject:entity];
        
    }if ([parkEntity.attraction_class indexOfObject:[NSNumber numberWithInt:15]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"游客服务中心";
        entity.type = @"15";
        [moreArray addObject:entity];
        
    }
    if ([parkEntity.business_class indexOfObject:[NSNumber numberWithDouble:2.1]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"住宿";
        entity.type = @"21";
        [_arrayBusinessMore addObject:entity];
        
    }
    if ([parkEntity.business_class indexOfObject:[NSNumber numberWithDouble:2.2]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"餐饮";
        entity.type = @"22";
        [_arrayBusinessMore addObject:entity];
        
    }
    if ([parkEntity.business_class indexOfObject:[NSNumber numberWithDouble:2.3]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"休闲";
        entity.type = @"23";
        [_arrayBusinessMore addObject:entity];
        
    }
    if ([parkEntity.business_class indexOfObject:[NSNumber numberWithDouble:2.4]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"娱乐";
        entity.type = @"24";
        [_arrayBusinessMore addObject:entity];
        
    }
    if ([parkEntity.business_class indexOfObject:[NSNumber numberWithDouble:2.5]]!= NSNotFound) {
        GXScrollEntity * entity = [[GXScrollEntity alloc] init];
        entity.name = @"商店";
        entity.type = @"25";
        [_arrayBusinessMore addObject:entity];
        
    }
    [self createView];
    [self createPath];
}
-(void)setViewPop:(UIView *)viewPop{
    _viewPop = viewPop;
    viewPop.hidden = YES;
}
-(void)viewWillAppear:(BOOL)animated {
    [_mapView viewWillAppear];
    [JDStatusBarNotification dismissAnimated:YES];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    _locService.delegate = self;
    _routesearch.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
    [SpotDetailViewController sharedInstance].isAppear = YES;
    [super viewWillAppear:animated];

    [MobClick beginLogPageView:@"MapBaiduViewController"];
}

-(void)viewWillDisappear:(BOOL)animated {
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
    _locService.delegate = nil;
     _routesearch.delegate = nil; // 不用时，置nil
//    _playView.layer.transform = CATransform3DIdentity;
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"MapBaiduViewController"];
    [SpotDetailViewController sharedInstance].isAppear = NO;
}

- (void)dealloc {
    
    if (_routesearch != nil) {
        _routesearch = nil;
    }
    
    if (_mapView) {
        _mapView = nil;
    }
}

- (void) setAnnotionsWithList:(NSString *)pType {

    [_mapView removeAnnotations:mutableArraySpot];
    
    [mutableArraySpot removeAllObjects];
    
    CLLocationDegrees latitude = [userSpotEntity.latitude doubleValue];
    CLLocationDegrees longtitude = [userSpotEntity.longitude doubleValue];
    
    BasicMapAnnotation *annotiation = [[BasicMapAnnotation alloc] initMapAnnotation:latitude
                                                                       andLongitude:longtitude
                                                                            Content:userSpotEntity.content
                                                                              Title:userSpotEntity.title
                                                                              Ptype:userSpotEntity.ptype
                                                                        business_id:userSpotEntity.business_id
                                                                      andInfoNumber:0];
    [mutableArraySpot addObject:annotiation];
    
    for (int i = 0; i < [mutableArray count]; i++) {
        SpotEntity *entity = [mutableArray objectAtIndex:i];
        
        if ([pType isEqualToString:entity.ptype] == YES) {
            CLLocationDegrees latitude = [entity.latitude doubleValue];
            CLLocationDegrees longtitude = [entity.longitude doubleValue];
            if (latitude ==0||longtitude ==0) {
                continue;
            }
            BasicMapAnnotation *annotiation = annotiation = [[BasicMapAnnotation alloc] initMapAnnotation:latitude
                                                                                             andLongitude:longtitude
                                                                                                  Content:entity.content
                                                                                                    Title:entity.title
                                                                                                    Ptype:entity.ptype
                                                                                              business_id:entity.business_id
                                                                                            andInfoNumber:i+1];
            
            [mutableArraySpot addObject:annotiation];
            
            DebugLog(@"%@,%@,%@", entity.ptype,entity.latitude, entity.longitude);
            
            [_mapView addAnnotation:annotiation];
        }
    }
}
-(void)decideBlock:(isSelectedBlock)block
{
    _block = block ;
}
-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
    static NSString *indentifier=@"basicMapAnnotation";
    
    if ([annotation isKindOfClass:[RouteAnnotation class]]) {
        
        return [self getRouteAnnotationView:mapView viewForAnnotation:(RouteAnnotation*)annotation];
        
    } else if ([annotation isKindOfClass:[BasicMapAnnotation class]]) {
        
        BMKAnnotationView *annView=[mapView dequeueReusableAnnotationViewWithIdentifier:indentifier];
        if (!annView) {
            annView=[[BMKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:indentifier];
        }
        annView.canShowCallout = NO;//在点击大头针的时候会弹出那个黑框框
        annView.draggable = NO;//这里决定annView能不能拖动，应该经常会把它设为NO
        
        BasicMapAnnotation *an = (BasicMapAnnotation *)annotation;
        
        if ([an.ptype isEqualToString:@"1"] == YES) {
            annView.image = [UIImage imageNamed:@"地图图标_景点@2x"];
        } else if ([an.ptype isEqualToString:@"2"] == YES) {
            annView.image = [UIImage imageNamed:@"地图图标_商业@2x"];
        } else if ([an.ptype isEqualToString:@"3"] == YES) {
            annView.image = [UIImage imageNamed:@"地图图标_厕所@2x"];
        } else if ([an.ptype isEqualToString:@"5"] == YES) {
            annView.image = [UIImage imageNamed:@"医务室"];
        }else if ([an.ptype isEqualToString:@"6"] == YES) {
            annView.image = [UIImage imageNamed:@"出入口50%"];
        }else if ([an.ptype isEqualToString:@"7"] == YES) {
            annView.image = [UIImage imageNamed:@"休息区"];
        }else if ([an.ptype isEqualToString:@"8"] == YES) {
            annView.image = [UIImage imageNamed:@"停车场50%"];
        }else if ([an.ptype isEqualToString:@"9"] == YES) {
            annView.image = [UIImage imageNamed:@"售票处"];
        }else if ([an.ptype isEqualToString:@"10"] == YES) {
            annView.image = [UIImage imageNamed:@"游船"];
        }else if ([an.ptype isEqualToString:@"11"] == YES) {
            annView.image = [UIImage imageNamed:@"电瓶车"];
        }else if ([an.ptype isEqualToString:@"12"] == YES) {
            annView.image = [UIImage imageNamed:@"餐饮"];
        }else if ([an.ptype isEqualToString:@"13"] == YES) {
            annView.image = [UIImage imageNamed:@"游览车站"];
        }else if ([an.ptype isEqualToString:@"14"] == YES) {
            annView.image = [UIImage imageNamed:@"警卫处"];
        } else if ([an.ptype isEqualToString:@"15"] == YES) {
            annView.image = [UIImage imageNamed:@"游客服务中心"];
        }
        else if ([an.ptype isEqualToString:@"2.1"] == YES) {
            annView.image = [UIImage imageNamed:@"住宿"];
        }else if ([an.ptype isEqualToString:@"2.2"] == YES) {
            annView.image = [UIImage imageNamed:@"餐饮-1"];
        }else if ([an.ptype isEqualToString:@"2.3"] == YES) {
            annView.image = [UIImage imageNamed:@"休闲"];
        }else if ([an.ptype isEqualToString:@"2.4"] == YES) {
            annView.image = [UIImage imageNamed:@"娱乐"];
        }else if ([an.ptype isEqualToString:@"2.5"] == YES) {
            annView.image = [UIImage imageNamed:@"商店"];
        }
        
        for (UIView *view in [annView subviews]) {
            [view removeFromSuperview];
        }
        
        return annView;
    } else {
        BMKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:indentifier];
        if (annotationView == nil) {
            annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:indentifier];
            ((BMKPinAnnotationView*)annotationView).pinColor = BMKPinAnnotationColorRed;
            ((BMKPinAnnotationView*)annotationView).animatesDrop = YES;
        }
        
        annotationView.centerOffset = CGPointMake(0, -(annotationView.frame.size.height * 0.5));
        annotationView.annotation = annotation;
        annotationView.canShowCallout = TRUE;
        return annotationView;
    }
}

-(void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view {
    
    if ([view.annotation isKindOfClass:[BasicMapAnnotation class]])
    {
        BasicMapAnnotation *basicAnnotation=(BasicMapAnnotation *)view.annotation;
        NSString *strContent = [NSString stringWithFormat:@"%@", basicAnnotation.content];
        self.playMusicEntity = [mutableArray objectAtIndex:basicAnnotation.number-1];
        
        int index = 0;
        BOOL add = YES;
        NSMutableArray *array = [[NSMutableArray alloc] init];
        for (int i = 0; i < [mutableArray count]; i++) {
            SpotEntity *entity2 = [mutableArray objectAtIndex:i];
            
            if ([@"1" isEqualToString:entity2.ptype] == YES) {
                [array addObject:entity2];
                if (self.playMusicEntity == entity2) {
                    add = NO;
                }
                
                if (add == YES) {
                    index++;
                }
            }
        }

        MapDXAlertView *alert = nil;
        NSString *business_title = @"";
        if ([basicAnnotation.ptype isEqualToString:@"1"] == YES) {
//            if ([AppDelegate instance].file_from_local == YES) {
//                NSString *localImagePath = [CommonService addLocalRootPath:entity.album ParkId:parkEntity.ID];
//                DebugLog(@"%@", localImagePath);
//                UIImage* img = [UIImage imageWithContentsOfFile:localImagePath];
//                alert = [[MapDXAlertView alloc] initWithTitle:basicAnnotation.title contentText:strContent leftButtonTitle:@"步行导航" rightButtonTitle:@"语音讲解" topImage:img];
//            }
            if (autoPlayType == AutoPlayTypeYes) {
                __weak __typeof(self)weakSelf  = self;
                UIAlertView * alertAuto = [[UIAlertView alloc] initWithTitle:@"提示" message:@"景区介绍需关闭Auto语音讲解功能" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                alertAuto.tag = 3333;
                [self decideBlock:^(BOOL isYES) {
                    if (isYES) {
                        musicSpotEntity = _playMusicEntity;
                        [weakSelf autoPlayAudioWithSpotEntity:musicSpotEntity];
                    };
                }];
                [alertAuto show];
            }else{
                musicSpotEntity = _playMusicEntity;
                [self autoPlayAudioWithSpotEntity:musicSpotEntity];
            }
            
        }else if ([basicAnnotation.ptype containsString:@"."] == YES){
            
            
            if ([basicAnnotation.ptype isEqualToString:@"2.1"] == YES){
                business_title = @"住宿";
            }else if ([basicAnnotation.ptype isEqualToString:@"2.2"] == YES){
                business_title = @"餐饮";
            }else if ([basicAnnotation.ptype isEqualToString:@"2.3"] == YES){
                business_title = @"休闲";
            }else if ([basicAnnotation.ptype isEqualToString:@"2.4"] == YES){
                business_title = @"娱乐";
            }else if ([basicAnnotation.ptype isEqualToString:@"2.5"] == YES){
                business_title = @"商店";
            }
//            basicAnnotation.business_id = @"17";
            if ([basicAnnotation.business_id isEqualToString:@"0"]||[basicAnnotation.business_id isEqualToString:@""]||!basicAnnotation.business_id) {
                alert = [[MapDXAlertView alloc] initWithTitle:business_title contentText:basicAnnotation.title leftButtonTitle:nil rightButtonTitle:@"导航" topImage:nil orUrlString:nil];
                
            }else{
//                if ([AppDelegate instance].file_from_local == YES) {
//                    NSString *localImagePath = [CommonService addLocalRootPath:self.playMusicEntity.album ParkId:parkEntity.ID];
//                    DebugLog(@"%@", localImagePath);
//                    UIImage* img = [UIImage imageWithContentsOfFile:localImagePath];
//                    alert = [[MapDXAlertView alloc] initWithTitle:basicAnnotation.title contentText:strContent leftButtonTitle:@"步行导航" rightButtonTitle:@"详情" topImage:img];
//                }
//                UIImageView *imgv = [[UIImageView alloc]init];
//                [imgv sd_setImageWithURL:[NSURL URLWithString:self.playMusicEntity.album]];
                alert = [[MapDXAlertView alloc] initWithTitle:basicAnnotation.title contentText:strContent leftButtonTitle:@"步行导航" rightButtonTitle:@"详情" topImage:nil orUrlString:self.playMusicEntity.album];

            }
        }else {
            NSString *title = @"厕所";
            if ([basicAnnotation.ptype isEqualToString:@"2"] == YES) {
                title = @"商业";
            }else if ([basicAnnotation.ptype isEqualToString:@"5"] == YES){
                title = @"医务室";
            }else if ([basicAnnotation.ptype isEqualToString:@"6"] == YES){
                title = @"出入口";
            }else if ([basicAnnotation.ptype isEqualToString:@"7"] == YES){
                title = @"休息区";
            }else if ([basicAnnotation.ptype isEqualToString:@"8"] == YES){
                title = @"停车场";
            }else if ([basicAnnotation.ptype isEqualToString:@"9"] == YES){
                title = @"售票处";
            }else if ([basicAnnotation.ptype isEqualToString:@"10"] == YES){
                title = @"游船登陆点";
            }else if ([basicAnnotation.ptype isEqualToString:@"11"] == YES){
                title = @"电瓶车乘车点";
            }else if ([basicAnnotation.ptype isEqualToString:@"12"] == YES){
                title = @"餐饮服务点";
            }else if ([basicAnnotation.ptype isEqualToString:@"13"] == YES){
                title = @"游览车站";
            }else if ([basicAnnotation.ptype isEqualToString:@"14"] == YES){
                title = @"警卫处";
            }else if ([basicAnnotation.ptype isEqualToString:@"15"] == YES){
                title = @"游客服务中心";
            }
            alert = [[MapDXAlertView alloc] initWithTitle:title contentText:basicAnnotation.title leftButtonTitle:nil rightButtonTitle:@"导航" topImage:nil orUrlString:nil];
        }
        
        [alert show];
        alert.leftBlock = ^() {
            NSLog(@"left button clicked");
            
            spotEntityStart = [[BasicMapAnnotation alloc] init];
            spotEntityStart.latitude = _autoLocation.location.coordinate.latitude;
            spotEntityStart.longitude = _autoLocation.location.coordinate.longitude;
            spotEntityStart.title = @"当前位置";
            
            spotEntityEnd = [[BasicMapAnnotation alloc] init];
            spotEntityEnd.latitude = basicAnnotation.latitude;
            spotEntityEnd.longitude = basicAnnotation.longitude;
            spotEntityEnd.title = basicAnnotation.title;
            
            [self walkRoute];
        };
        alert.rightBlock = ^() {
            
            if ([basicAnnotation.ptype isEqualToString:@"1"] == NO) {
                if (basicAnnotation.business_id && ![basicAnnotation.business_id isEqualToString:@"0"]){
                    AroundHotelViewController *vc = [[AroundHotelViewController alloc] init];
                    vc.longitude = [NSString stringWithFormat:@"%f", _autoLocation.location.coordinate.longitude];
                    vc.latitude  = [NSString stringWithFormat:@"%f", _autoLocation.location.coordinate.longitude];
                    vc.parkEntity = parkEntity;
                    vc.businessid = basicAnnotation.business_id;
                    vc.strTitle = business_title;
                    [self.navigationController pushViewController:vc animated:YES];
                    return;
                }

                spotEntityStart = [[BasicMapAnnotation alloc] init];
                spotEntityStart.latitude = _autoLocation.location.coordinate.latitude;
                spotEntityStart.longitude = _autoLocation.location.coordinate.longitude;
                spotEntityStart.title = @"当前位置";
                
                spotEntityEnd = [[BasicMapAnnotation alloc] init];
                spotEntityEnd.latitude = basicAnnotation.latitude;
                spotEntityEnd.longitude = basicAnnotation.longitude;
                spotEntityEnd.title = basicAnnotation.title;
                
                [self walkRoute];
                
                return;
            }
            NSLog(@"right button clicked");

//            SpotDetailViewController *vc = [SpotDetailViewController sharedInstance];
//            vc.musicArrayNumber = index;
//            vc.parkEntity = parkEntity;
//            vc.musicArray = array;
//            vc.entity = entity;
//            [self.navigationController pushViewController:vc animated:YES];
          
          
        };
        alert.dismissBlock = ^() {
            NSLog(@"Do something interesting after dismiss block");
        };
        if ([basicAnnotation.ptype isEqualToString:@"1"]) {
           
        }
    }
    
    [_mapView deselectAnnotation:view.annotation animated:YES];

}
- (IBAction)runNavigation:(id)sender {
    spotEntityStart = [[BasicMapAnnotation alloc] init];
    spotEntityStart.latitude = _autoLocation.location.coordinate.latitude;
    spotEntityStart.longitude = _autoLocation.location.coordinate.longitude;
    spotEntityStart.title = @"当前位置";
    if (autoPlayType == AutoPlayTypeNo) {
        spotEntityEnd = [[BasicMapAnnotation alloc] init];
        spotEntityEnd.latitude = [self.playMusicEntity.latitude doubleValue];
        spotEntityEnd.longitude = [self.playMusicEntity.longitude doubleValue];
        spotEntityEnd.title = self.playMusicEntity.title;
    }else{
        spotEntityEnd = [[BasicMapAnnotation alloc] init];
        spotEntityEnd.latitude = [musicSpotEntity.latitude doubleValue];
        spotEntityEnd.longitude = [musicSpotEntity.longitude doubleValue];
        spotEntityEnd.title = musicSpotEntity.title;
    }
    
    
    [self walkRoute];
}

-(void)mapView:(BMKMapView *)mapView didDeselectAnnotationView:(BMKAnnotationView *)view{
    NSLog(@"deselect");
//    if (_currentZoomLevel == _mapView.zoomLevel) {
//        BMKAnnotationView *annView = (BMKAnnotationView *)view;
    
//        if ([decType isEqualToString:@"1"] == YES) {
//            annView.image = [UIImage imageNamed:@"地图图标_景点@2x"];
//        } else if ([decType isEqualToString:@"2"] == YES) {
//            annView.image = [UIImage imageNamed:@"地图图标_商业@2x"];
//        } else if ([decType isEqualToString:@"3"] == YES) {
//            annView.image = [UIImage imageNamed:@"地图图标_厕所@2x"];
//        } else if ([decType isEqualToString:@"5"] == YES) {
//            annView.image = [UIImage imageNamed:@"医务室"];
//        }else if ([decType isEqualToString:@"6"] == YES) {
//            annView.image = [UIImage imageNamed:@"出入口50%"];
//        }else if ([decType isEqualToString:@"7"] == YES) {
//            annView.image = [UIImage imageNamed:@"休息区"];
//        }else if ([decType isEqualToString:@"8"] == YES) {
//            annView.image = [UIImage imageNamed:@"停车场50%"];
//        }else if ([decType isEqualToString:@"9"] == YES) {
//            annView.image = [UIImage imageNamed:@"售票处"];
//        }else if ([decType isEqualToString:@"10"] == YES) {
//            annView.image = [UIImage imageNamed:@"游船"];
//        }else if ([decType isEqualToString:@"11"] == YES) {
//            annView.image = [UIImage imageNamed:@"电瓶车"];
//        }else if ([decType isEqualToString:@"12"] == YES) {
//            annView.image = [UIImage imageNamed:@"餐饮"];
//        }else if ([decType isEqualToString:@"13"] == YES) {
//            annView.image = [UIImage imageNamed:@"游览车站"];
//        }else if ([decType isEqualToString:@"14"] == YES) {
//            annView.image = [UIImage imageNamed:@"警卫处"];
//        }else if ([decType isEqualToString:@"15"] == YES) {
//            annView.image = [UIImage imageNamed:@"游客服务中心"];
//        }
//        else if ([decType isEqualToString:@"2.1"] == YES) {
//            annView.image = [UIImage imageNamed:@"住宿"];
//        }else if ([decType isEqualToString:@"2.2"] == YES) {
//            annView.image = [UIImage imageNamed:@"餐饮-1"];
//        }else if ([decType isEqualToString:@"2.3"] == YES) {
//            annView.image = [UIImage imageNamed:@"休闲"];
//        }else if ([decType isEqualToString:@"2.4"] == YES) {
//            annView.image = [UIImage imageNamed:@"娱乐"];
//        }else if ([decType isEqualToString:@"2.5"] == YES) {
//            annView.image = [UIImage imageNamed:@"商店"];
//        }

//    } else {
//        _currentZoomLevel = _mapView.zoomLevel;
//    }
    
}

/**
 *在地图View将要启动定位时，会调用此函数
 *@param mapView 地图View
 */
- (void)mapViewWillStartLocatingUser:(BMKMapView *)mapView
{
    NSLog(@"start locate");
}

/**
 *用户方向更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation
{
    [_mapView updateLocationData:userLocation];
//    NSLog(@"didUpdateUserHeading lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
//    NSLog(@"heading is %@",userLocation.heading);
}



/**
 *用户位置更新后，会调用此函数
 *@param userLocation 新的用户位置
 */
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation
{
    
    NSLog(@"didUpdateBMKUserLocation ++++ lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    
    
    _autoLocation = userLocation;
//    if (locationOnce) {
//        locationOnce = NO;
//        [self doChange];
//    }
    _mapView.showsUserLocation = YES;//显示定位图层
    [_mapView updateLocationData:userLocation];
    BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude));
//    BMKMapPoint point2 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(32.4035317085,119.4543000906));
    if (isCircle) {
        
        DebugLog(@"正在循环与========");
        oneTime = NO;
        for (int i = 0;i < [musicArrayList count]; i++) {
            SpotEntity *entity = [musicArrayList objectAtIndex:i];
            double lat2 = [entity.latitude doubleValue];
            double lon2 = [entity.longitude doubleValue];
            BMKMapPoint point3 = BMKMapPointForCoordinate(CLLocationCoordinate2DMake(lat2,lon2));
            CLLocationDistance distance = BMKMetersBetweenMapPoints(point3,point2);
            if (distance < [entity.radius doubleValue]) {
                [_arrayMusicNumber addObject:entity];
            }
        }
        
        
        if ([_arrayMusicNumber count]==1) {
            
            if (![sameArray isEqualToArray:_arrayMusicNumber]){
                isCircle = NO;
                sameArray = [NSMutableArray arrayWithArray:_arrayMusicNumber];
                musicSpotEntity = [_arrayMusicNumber objectAtIndex:0];
                
                
                [self autoPlayAudioWithSpotEntity:musicSpotEntity ];
                
            }else{
                [_arrayMusicNumber removeAllObjects];
            }
        }else if ([_arrayMusicNumber count]>1) {
            
            isCircle = NO;
            UIAlertView *alert =[[UIAlertView alloc] initWithTitle:nil message:@"景点选择" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
            /**
             修改景点选择bug，之前数组一开始肯定为空
             */
            NSMutableArray *resultArr = [[NSMutableArray alloc]init];
            for (int k = 0; k<[_arrayMusicNumber count]; k++) {
                SpotEntity *entity3 = [_arrayMusicNumber objectAtIndex:k];
                if (![resultArr containsObject:entity3.title]) {
                    [resultArr addObject:entity3.title];
                }
//                for (int i = 0; i < alert.numberOfButtons; i++) {
//                    if ([[alert buttonTitleAtIndex:i] isEqualToString:entity3.title])
//                    {
//                        break;
//                    }
//                    if (i == alert.numberOfButtons -1)
//                    {
//                        [alert addButtonWithTitle:entity3.title];
//                    }
//                }
            }
            for (int i = 0; i < resultArr.count; i ++) {
                [alert addButtonWithTitle:resultArr[i]];
            }
           
            alert.tag = 2222;
            [alert show];
            
        }else{
            
            autoStart = YES;
            
            
        }
    }

    
}


/**
 *在地图View停止定位后，会调用此函数
 *@param mapView 地图View
 */
- (void)mapViewDidStopLocatingUser:(BMKMapView *)mapView
{
    NSLog(@"stop locate");
}

/**
 *定位失败后，会调用此函数
 *@param mapView 地图View
 *@param error 错误号，参考CLError.h中定义的错误号
 */
- (void)mapView:(BMKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
{
    NSLog(@"location error");
}

//- (void) getSpotFromInternetData {
//    
//    CommonService *service = [[CommonService alloc] init];
//    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
//                           parkEntity.ID, @"parkid", nil];
//    
//    [service getNetWorkData:param
//                       Path:SPOTPATH
//                  Successed:^(id entity) {
//                      NSDictionary *dic = (NSDictionary *)entity;
//                      NSArray *array = [dic objectForKey:@"attractionRows"];
//                      
//                      for (NSDictionary* attributes in array) {
//                          SpotEntity *entity2 = [[SpotEntity alloc] init];
//                          entity2 = [entity2 initWithAttributes:attributes];
//                          [mutableArraySpot addObject:entity2];
//                      }
//                      
//                      array = [dic objectForKey:@"businessRows"];
//                      
//                      for (NSDictionary* attributes in array) {
//                          SpotEntity *entity2 = [[SpotEntity alloc] init];
//                          entity2 = [entity2 initWithAttributes:attributes];
//                          [[AppDelegate instance].arrayBusiness addObject:entity2];
//                      }
//                      
//                      array = [dic objectForKey:@"toiletRows"];
//                      
//                      for (NSDictionary* attributes in array) {
//                          SpotEntity *entity2 = [[SpotEntity alloc] init];
//                          entity2 = [entity2 initWithAttributes:attributes];
//                          [[AppDelegate instance].arrayToilet addObject:entity2];
//                      }
//                      [self setAnnotionsWithList:@"1"];
//                      
//                      [indicator stopAnimationWithLoadText:@"加载完成..." withType:YES];
//                  } Failed:^(NSInteger errorCode, NSString *message) {
//                      [indicator stopAnimationWithLoadText:@"加载完成..." withType:YES];
//                  }];
//}

- (IBAction)doSpotAction:(id)sender {
    [self initBottomView:0];
    [self setAnnotionsWithList:@"1"];
    _viewPop.hidden = YES;
    _businessView.hidden = YES;
    _popViewAngel.hidden = YES;
}

- (IBAction)doBusinessAction:(id)sender {
    [self initBottomView:1];

    if ([_arrayBusinessMore count] !=0) {
        _businessView.hidden = NO;
        _popViewAngel.hidden = NO;
    }else{
        [self setAnnotionsWithList:@"2"];
    }
    
    _viewPop.hidden = YES;
    [self clean];
}

- (IBAction)doToiletAction:(id)sender {
    [self initBottomView:2];
    [self setAnnotionsWithList:@"3"];
    _businessView.hidden = YES;
    _popViewAngel.hidden = YES;
    _viewPop.hidden = YES;
    [self clean];
}
-(void)doHospitalAction
{
    [self setAnnotionsWithList:@"5"];
}
-(void)doEnterAction
{
    [self setAnnotionsWithList:@"6"];
}
-(void)doRestAction
{
    [self setAnnotionsWithList:@"7"];
}
-(void)doParkCarAction
{
    [self setAnnotionsWithList:@"8"];
}
-(void)doSellTicketAction
{
    [self setAnnotionsWithList:@"9"];
}
-(void)doMapAnnoationActionWithString:(NSString *)tag
{
    [self setAnnotionsWithList:tag];
}


-(IBAction)doOtherAction:(id)sender
{
    [self initBottomView:4];
    _businessView.hidden = YES;
    _popViewAngel.hidden = YES;
    if ([moreArray count]==0) {
        _viewPop.hidden = YES;
    }else{
        
        _viewPop.hidden = NO;
        
        if (! scroll  ) {
            scroll = [[GXScrollView alloc]initWithEntityArray:moreArray];
            scroll.tag =4000;
            scroll.gxDelegate =self;
            [_viewPop addSubview:scroll];
            
            CGFloat top = 3; // 顶端盖高度
            CGFloat bottom = 3 ; // 底端盖高度
            CGFloat left = 20; // 左端盖宽度
            CGFloat right = 40; // 右端盖宽度
            UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
            // 指定为拉伸模式，伸缩后重新赋值
            _imageCut.image = [_imageCut.image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
            //            _imageCut.frame = CGRectMake(0, 0, CGRectGetMaxX(scroll.frame)+8, 48);
            _height4.constant = CGRectGetMaxX(scroll.frame)+8;
            _height5.constant = CGRectGetMaxX(scroll.frame)+8;
            NSLog(@"%f,%f",_imageCut.frame.size.width,_imageCut.frame.size.height);
        }
    }
 
}
- (void)doRouteAction{
    textFieldPop = 3;
    [pickerView reloadAllComponents];
    if ([mutableArrayRoad count] == 0) {
        ALERT_ERR_MSG(@"没有推荐线路");
    } else {
        [self tappedSelect:nil];
    }
}

- (void)initBottomView:(int) tab {
    
    if (tab == 0) {
        
        [btnSpot setBackgroundImage:[UIImage imageNamed:@"景点+"] forState:UIControlStateNormal];
        [btnBusiness setBackgroundImage:[UIImage imageNamed:@"商业-"] forState:UIControlStateNormal];
        [btnToilet setBackgroundImage:[UIImage imageNamed:@"厕所-"] forState:UIControlStateNormal];
        [btnOther setBackgroundImage:[UIImage imageNamed:@"其他-"] forState:UIControlStateNormal];
        [btnRoute setBackgroundImage:[UIImage imageNamed:@"地图_17"] forState:UIControlStateNormal];
        
        btnSpotText.titleLabel.textColor = [UIColor colorWithRed:0.32 green:0.77 blue:0.24 alpha:1];
        btnBusinessText.titleLabel.textColor = [UIColor darkGrayColor];
        btnToiletText.titleLabel.textColor = [UIColor darkGrayColor];
        btnOtherText.titleLabel.textColor = [UIColor darkGrayColor];
        btnRouteText.titleLabel.textColor = [UIColor darkGrayColor];
        [scroll clearColor];
        [_businessScroll clearColor];
    } else if (tab == 1) {
        [scroll clearColor];
        [btnSpot setBackgroundImage:[UIImage imageNamed:@"景点-"] forState:UIControlStateNormal];
        [btnBusiness setBackgroundImage:[UIImage imageNamed:@"商业"] forState:UIControlStateNormal];
        [btnToilet setBackgroundImage:[UIImage imageNamed:@"厕所-"] forState:UIControlStateNormal];
        [btnOther setBackgroundImage:[UIImage imageNamed:@"其他-"] forState:UIControlStateNormal];
        [btnRoute setBackgroundImage:[UIImage imageNamed:@"地图_17"] forState:UIControlStateNormal];
        
        btnSpotText.titleLabel.textColor = [UIColor darkGrayColor];
        btnBusinessText.titleLabel.textColor = [UIColor colorWithRed:0.32 green:0.77 blue:0.24 alpha:1];
        btnToiletText.titleLabel.textColor = [UIColor darkGrayColor];
        btnOtherText.titleLabel.textColor = [UIColor darkGrayColor];
        btnRouteText.titleLabel.textColor = [UIColor darkGrayColor];
    } else if (tab == 2) {
        [scroll clearColor];
        [_businessScroll clearColor];
        [btnSpot setBackgroundImage:[UIImage imageNamed:@"景点-"] forState:UIControlStateNormal];
        [btnBusiness setBackgroundImage:[UIImage imageNamed:@"商业-"] forState:UIControlStateNormal];
        [btnToilet setBackgroundImage:[UIImage imageNamed:@"厕所"] forState:UIControlStateNormal];
        [btnOther setBackgroundImage:[UIImage imageNamed:@"其他-"] forState:UIControlStateNormal];
        [btnRoute setBackgroundImage:[UIImage imageNamed:@"地图_17"] forState:UIControlStateNormal];
        
        btnSpotText.titleLabel.textColor = [UIColor darkGrayColor];
        btnBusinessText.titleLabel.textColor = [UIColor darkGrayColor];
        btnToiletText.titleLabel.textColor = [UIColor colorWithRed:0.32 green:0.77 blue:0.24 alpha:1];
        btnOtherText.titleLabel.textColor = [UIColor darkGrayColor];
        btnRouteText.titleLabel.textColor = [UIColor darkGrayColor];
    }else if (tab == 3) {
        [btnSpot setBackgroundImage:[UIImage imageNamed:@"景点-"] forState:UIControlStateNormal];
        [btnBusiness setBackgroundImage:[UIImage imageNamed:@"商业-"] forState:UIControlStateNormal];
        [btnToilet setBackgroundImage:[UIImage imageNamed:@"厕所-"] forState:UIControlStateNormal];
        [btnOther setBackgroundImage:[UIImage imageNamed:@"其他"] forState:UIControlStateNormal];
        [btnRoute setBackgroundImage:[UIImage imageNamed:@"地图_17"] forState:UIControlStateNormal];
        
        btnSpotText.titleLabel.textColor = [UIColor darkGrayColor];
        btnBusinessText.titleLabel.textColor = [UIColor darkGrayColor];
        btnToiletText.titleLabel.textColor = [UIColor darkGrayColor];
        btnOtherText.titleLabel.textColor = [UIColor colorWithRed:0.32 green:0.77 blue:0.24 alpha:1];
        btnRouteText.titleLabel.textColor = [UIColor darkGrayColor];
        [_businessScroll clearColor];
    }else if (tab == 4) {
        [btnSpot setBackgroundImage:[UIImage imageNamed:@"景点-"] forState:UIControlStateNormal];
        [btnBusiness setBackgroundImage:[UIImage imageNamed:@"商业-"] forState:UIControlStateNormal];
        [btnToilet setBackgroundImage:[UIImage imageNamed:@"厕所-"] forState:UIControlStateNormal];
        [btnOther setBackgroundImage:[UIImage imageNamed:@"其他"] forState:UIControlStateNormal];
        [btnRoute setBackgroundImage:[UIImage imageNamed:@"地图_11"] forState:UIControlStateNormal];
        [_businessScroll clearColor];
        btnSpotText.titleLabel.textColor = [UIColor darkGrayColor];
        btnBusinessText.titleLabel.textColor = [UIColor darkGrayColor];
        btnToiletText.titleLabel.textColor = [UIColor darkGrayColor];
        btnOtherText.titleLabel.textColor = [UIColor colorWithRed:0.32 green:0.77 blue:0.24 alpha:1];
        btnRouteText.titleLabel.textColor = [UIColor colorWithRed:0.32 green:0.77 blue:0.24 alpha:1];
    }
}

- (void)popSpotMenu {
    [UIView animateWithDuration:.35 animations:^{
        //self.viewPopMenu.backgroundColor = RGBACOLOR(0, 0, 0, .9);
        self.viewPopMenu.alpha = 1.0;
        [UIView animateWithDuration:.25 animations:^{
            [self.viewPopMenu setFrame:CGRectMake(self.viewPopMenu.frame.origin.x, ScreenHeight-self.viewPopMenu.frame.size.height, self.viewPopMenu.frame.size.width, self.viewPopMenu.frame.size.height)];
        }];
    } completion:^(BOOL finished) {
        
    }];
}

- (IBAction)tappedSelect: (id)sender {
    
    if (textFieldPop == 1) {
//        NSInteger fillingRow = [pickerView selectedRowInComponent:0];//第一列选择的行
       MapRouteViewController *vc = [[MapRouteViewController alloc]init];
        vc.stringTitle = @"起点选择";
        vc.arrayTitle = mutableArraySpot;
        [vc transIndexBlock:^(NSInteger index) {
            spotEntityStart = [mutableArraySpot objectAtIndex:index];
            self.textFieldStart.text = spotEntityStart.title;
        }];
        [self presentViewController:vc animated:YES completion:nil];
//        spotEntityStart = [mutableArraySpot objectAtIndex:fillingRow];
    } else if (textFieldPop == 2) {
//        NSInteger fillingRow = [pickerView selectedRowInComponent:0];//第一列选择的行
//        spotEntityEnd = [mutableArraySpot objectAtIndex:fillingRow];
        MapRouteViewController *vc2 = [[MapRouteViewController alloc]init];
        vc2.stringTitle = @"终点选择";
        vc2.arrayTitle = mutableArraySpot;
        [vc2 transIndexBlock:^(NSInteger index) {
            spotEntityEnd = [mutableArraySpot objectAtIndex:index];
            self.textFieldEnd.text = spotEntityEnd.title;
        }];
        [self presentViewController:vc2 animated:YES completion:nil];
    } else {
        //路线图
      
        MapRouteViewController *vc2 = [[MapRouteViewController alloc]init];
        vc2.stringTitle = @"推荐路线";
        vc2.arrayTitle = mutableArrayRoad;
        [vc2 transIndexBlock:^(NSInteger index) {
            _mRoadLineEntity = [mutableArrayRoad objectAtIndex:index];

            if (_mRoadLineEntity == nil) {
                if ([mutableArrayRoad count] > 0) {
                    _mRoadLineEntity = [mutableArrayRoad objectAtIndex:0];
                }
            } else {
                [self onDriveSearch:_mRoadLineEntity.point];
            }
        }];
        [self presentViewController:vc2 animated:YES completion:nil];
    }
    
    if (textFieldPop == 1) {
//        self.textFieldStart.text = spotEntityStart.title;
    } else if (textFieldPop == 2) {
//        self.textFieldEnd.text = spotEntityEnd.title;
    } else {
            }
//    [self hidenPopMenu];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    
    if (textField == self.textFieldStart) {
       
            textFieldPop = 1;
            [pickerView reloadAllComponents];
//            [self popSpotMenu];
            [self tappedSelect:textField];
            return NO;
        
        
    } else if (textField == self.textFieldEnd) {
        
            textFieldPop = 2;
            [pickerView reloadAllComponents];
//            [self popSpotMenu];
            [self tappedSelect:textField];
            return NO;
        
        
    }
    
    return YES;
}

- (void)hidenPopMenu {
    [UIView animateWithDuration:.35 animations:^{
        [self.viewPopMenu setFrame:CGRectMake(0, ScreenHeight,ScreenWidth, viewPopMenu.frame.size.height)];
        self.viewPopMenu.alpha = 0;
    } completion:^(BOOL finished) {
        if (finished) {
            //[self.viewListSpot removeFromSuperview];
        }
    }];
}

- (IBAction)showLocation:(id)sender {
   
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        ALERT_ERR_MSG(@"使用地图功能需打开定位服务");
    }else{
    dispatch_queue_t concurrentQueue = dispatch_queue_create("my.concurrent.queue", DISPATCH_QUEUE_CONCURRENT);
    dispatch_sync(concurrentQueue, ^{
        _mapView.showsUserLocation = YES;
        [_mapView updateLocationData:_autoLocation];
        [_mapView setCenterCoordinate:_autoLocation.location.coordinate animated:YES];
    });
       
    }

}

- (IBAction)zoomBig:(id)sender {
    if (zoom++ > 20 ) {
        return;
    }
    [_mapView setZoomLevel:zoom];
    _currentZoomLevel = _mapView.zoomLevel;
}

- (IBAction)zoomSmall:(id)sender {
    if (zoom-- < 10) {
        return;
    }
    [_mapView setZoomLevel:zoom];
    _currentZoomLevel = _mapView.zoomLevel;
}


//----------------------------------------------------------------------------------------------------------
// pickerView 列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

// pickerView 每列个数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (textFieldPop == 1 || textFieldPop == 2) {
        return [mutableArraySpot count];
    } else {
        return [mutableArrayRoad count];
    }
}

// 每列宽度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    return ScreenWidth;
}
// 返回选中的行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (textFieldPop == 1) {
        spotEntityStart = [mutableArraySpot objectAtIndex:row];
    } else if (textFieldPop == 2) {
        spotEntityEnd = [mutableArraySpot objectAtIndex:row];
    } else {
        //路线图
        _mRoadLineEntity = [mutableArrayRoad objectAtIndex:row];
    }
}

//返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (textFieldPop == 1 || textFieldPop == 2) {
        SpotEntity *entity = [mutableArraySpot objectAtIndex:row];
        return entity.title;
    } else {
        RoadLineEntity *entity = [mutableArrayRoad objectAtIndex:row];
        return entity.title;
    }
}
//

//-------------------------------------------------------------------------------------------------------------
- (BMKAnnotationView*)getRouteAnnotationView:(BMKMapView *)mapview viewForAnnotation:(RouteAnnotation*)routeAnnotation
{
    BMKAnnotationView* view = nil;
    switch (routeAnnotation.type) {
        case 0:
        {
            view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"start_node"];
            if (view == nil) {
                view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"start_node"];
                view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_start.png"]];
                view.centerOffset = CGPointMake(0, -(view.frame.size.height * 0.5));
                view.canShowCallout = TRUE;
            }
            view.annotation = routeAnnotation;
        }
            break;
        case 1:
        {
            view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"end_node"];
            if (view == nil) {
                view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"end_node"];
                view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_end.png"]];
                view.centerOffset = CGPointMake(0, -(view.frame.size.height * 0.5));
                view.canShowCallout = TRUE;
            }
            view.annotation = routeAnnotation;
        }
            break;
        case 2:
        {
            view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"bus_node"];
            if (view == nil) {
                view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"bus_node"];
                view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_bus.png"]];
                view.canShowCallout = TRUE;
            }
            view.annotation = routeAnnotation;
        }
            break;
        case 3:
        {
            view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"rail_node"];
            if (view == nil) {
                view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"rail_node"];
                view.image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_rail.png"]];
                view.canShowCallout = TRUE;
            }
            view.annotation = routeAnnotation;
        }
            break;
        case 4:
        {
            view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"route_node"];
            if (view == nil) {
                view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"route_node"];
                view.canShowCallout = TRUE;
            } else {
                [view setNeedsDisplay];
            }
            
            UIImage* image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_direction.png"]];
            view.image = [image imageRotatedByDegrees:routeAnnotation.degree];
            view.annotation = routeAnnotation;
            
        }
            break;
        case 5:
        {
            view = [mapview dequeueReusableAnnotationViewWithIdentifier:@"waypoint_node"];
            if (view == nil)
            {
                view = [[BMKAnnotationView alloc]initWithAnnotation:routeAnnotation reuseIdentifier:@"waypoint_node"];
                view.canShowCallout = TRUE;
            } else
            {
                [view setNeedsDisplay];
            }
            
            UIImage* image = [UIImage imageWithContentsOfFile:[self getMyBundlePath1:@"images/icon_nav_waypoint.png"]];
            view.image = [image imageRotatedByDegrees:routeAnnotation.degree];
            view.annotation = routeAnnotation;
        }
            break;
        default:
            break;
    }
    
    return view;
}

- (BMKOverlayView*)mapView:(BMKMapView *)map viewForOverlay:(id<BMKOverlay>)overlay
{
    if ([overlay isKindOfClass:[BMKPolyline class]]) {
        BMKPolylineView* polylineView = [[BMKPolylineView alloc] initWithOverlay:overlay];
        polylineView.fillColor = [[UIColor colorWithRed:0.000f green:0.569f blue:1.000f alpha:1.00f] colorWithAlphaComponent:1];
        polylineView.strokeColor = [[UIColor colorWithRed:0.000f green:0.569f blue:1.000f alpha:1.00f] colorWithAlphaComponent:1];
        polylineView.lineWidth = 4.0;
        return polylineView;
    }
    return nil;
}

- (void)onGetTransitRouteResult:(BMKRouteSearch*)searcher result:(BMKTransitRouteResult*)result errorCode:(BMKSearchErrorCode)error
{
    NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
    [_mapView removeAnnotations:array];
    array = [NSArray arrayWithArray:_mapView.overlays];
    [_mapView removeOverlays:array];
    if (error == BMK_SEARCH_NO_ERROR) {
        BMKTransitRouteLine* plan = (BMKTransitRouteLine*)[result.routes objectAtIndex:0];
        // 计算路线方案中的路段数目
        int size = [plan.steps count];
        int planPointCounts = 0;
        for (int i = 0; i < size; i++) {
            BMKTransitStep* transitStep = [plan.steps objectAtIndex:i];
            if (i==0) {
                RouteAnnotation* item = [[RouteAnnotation alloc]init];
                item.coordinate = plan.starting.location;
                item.title = @"起点";
                item.type = 0;
                [_mapView addAnnotation:item]; // 添加起点标注
                
            } else if(i==size-1) {
                RouteAnnotation* item = [[RouteAnnotation alloc]init];
                item.coordinate = plan.terminal.location;
                item.title = @"终点";
                item.type = 1;
                [_mapView addAnnotation:item]; // 添加起点标注
            }
            RouteAnnotation* item = [[RouteAnnotation alloc]init];
            item.coordinate = transitStep.entrace.location;
            item.title = transitStep.instruction;
            item.type = 3;
            [_mapView addAnnotation:item];
            
            //轨迹点总数累计
            planPointCounts += transitStep.pointsCount;
        }
        
        //轨迹点
        BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];
        int i = 0;
        for (int j = 0; j < size; j++) {
            BMKTransitStep* transitStep = [plan.steps objectAtIndex:j];
            int k=0;
            for(k=0;k<transitStep.pointsCount;k++) {
                temppoints[i].x = transitStep.points[k].x;
                temppoints[i].y = transitStep.points[k].y;
                i++;
            }
            
        }
        // 通过points构建BMKPolyline
        BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];
        [_mapView addOverlay:polyLine]; // 添加路线overlay
        delete []temppoints;
        [self mapViewFitPolyLine:polyLine];
    }
}

- (void)onGetDrivingRouteResult:(BMKRouteSearch*)searcher result:(BMKDrivingRouteResult*)result errorCode:(BMKSearchErrorCode)error
{
    NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
    [_mapView removeAnnotations:array];
    array = [NSArray arrayWithArray:_mapView.overlays];
    [_mapView removeOverlays:array];
    if (error == BMK_SEARCH_NO_ERROR) {
        BMKDrivingRouteLine* plan = (BMKDrivingRouteLine*)[result.routes objectAtIndex:0];
        // 计算路线方案中的路段数目
        int size = [plan.steps count];
        int planPointCounts = 0;
        for (int i = 0; i < size; i++) {
            BMKDrivingStep* transitStep = [plan.steps objectAtIndex:i];
            if(i==0){
                RouteAnnotation* item = [[RouteAnnotation alloc]init];
                item.coordinate = plan.starting.location;
                item.title = @"起点";
                item.type = 0;
                [_mapView addAnnotation:item]; // 添加起点标注
                
            }else if(i==size-1){
                RouteAnnotation* item = [[RouteAnnotation alloc]init];
                item.coordinate = plan.terminal.location;
                item.title = @"终点";
                item.type = 1;
                [_mapView addAnnotation:item]; // 添加起点标注
            }
            //添加annotation节点
            RouteAnnotation* item = [[RouteAnnotation alloc]init];
            item.coordinate = transitStep.entrace.location;
            item.title = transitStep.entraceInstruction;
            item.degree = transitStep.direction * 30;
            item.type = 4;
            [_mapView addAnnotation:item];
            
            //轨迹点总数累计
            planPointCounts += transitStep.pointsCount;
        }
        // 添加途经点
        if (plan.wayPoints) {
            for (BMKPlanNode* tempNode in plan.wayPoints) {
                RouteAnnotation* item = [[RouteAnnotation alloc]init];
                item = [[RouteAnnotation alloc]init];
                item.coordinate = tempNode.pt;
                item.type = 5;
                item.title = tempNode.name;
                [_mapView addAnnotation:item];
            }
        }
        //轨迹点
        BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];
        int i = 0;
        for (int j = 0; j < size; j++) {
            BMKDrivingStep* transitStep = [plan.steps objectAtIndex:j];
            int k=0;
            for(k=0;k<transitStep.pointsCount;k++) {
                temppoints[i].x = transitStep.points[k].x;
                temppoints[i].y = transitStep.points[k].y;
                i++;
            }
            
        }
        // 通过points构建BMKPolyline
        BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];
        [_mapView addOverlay:polyLine]; // 添加路线overlay
        delete []temppoints;
        [self mapViewFitPolyLine:polyLine];
    }
    
    [super showLoadingView:NO];
}

- (void)onGetWalkingRouteResult:(BMKRouteSearch*)searcher result:(BMKWalkingRouteResult*)result errorCode:(BMKSearchErrorCode)error
{
    NSArray* array = [NSArray arrayWithArray:_mapView.annotations];
    [_mapView removeAnnotations:array];
    array = [NSArray arrayWithArray:_mapView.overlays];
    [_mapView removeOverlays:array];
    if (error == BMK_SEARCH_NO_ERROR) {
        BMKWalkingRouteLine* plan = (BMKWalkingRouteLine*)[result.routes objectAtIndex:0];
        int size = [plan.steps count];
        int planPointCounts = 0;
        for (int i = 0; i < size; i++) {
            BMKWalkingStep* transitStep = [plan.steps objectAtIndex:i];
            if(i==0){
                RouteAnnotation* item = [[RouteAnnotation alloc]init];
                item.coordinate = plan.starting.location;
                item.title = @"起点";
                item.type = 0;
                [_mapView addAnnotation:item]; // 添加起点标注
                
            }else if(i==size-1){
                RouteAnnotation* item = [[RouteAnnotation alloc]init];
                item.coordinate = plan.terminal.location;
                item.title = @"终点";
                item.type = 1;
                [_mapView addAnnotation:item]; // 添加起点标注
            }
            //添加annotation节点
            RouteAnnotation* item = [[RouteAnnotation alloc]init];
            item.coordinate = transitStep.entrace.location;
            item.title = transitStep.entraceInstruction;
            item.degree = transitStep.direction * 30;
            item.type = 4;
            [_mapView addAnnotation:item];
            
            //轨迹点总数累计
            planPointCounts += transitStep.pointsCount;
        }
        
        //轨迹点
        BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts];
        int i = 0;
        for (int j = 0; j < size; j++) {
            BMKWalkingStep* transitStep = [plan.steps objectAtIndex:j];
            int k=0;
            for(k=0;k<transitStep.pointsCount;k++) {
                temppoints[i].x = transitStep.points[k].x;
                temppoints[i].y = transitStep.points[k].y;
                i++;
            }
        }
        // 通过points构建BMKPolyline
        BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:temppoints count:planPointCounts];
        [_mapView addOverlay:polyLine]; // 添加路线overlay
        delete []temppoints;
        [self mapViewFitPolyLine:polyLine];
    }
    [super showLoadingView:NO];
}


-(IBAction)textFiledReturnEditing:(id)sender {
    [sender resignFirstResponder];
}

-(IBAction)onClickWalkSearch
{
    [super showLoadingView:YES];
    [self walkRoute];
}

- (void) walkRoute {
    
    BMKPlanNode* start = [[BMKPlanNode alloc]init];
    start.name = spotEntityStart.title;
    if ([spotEntityStart.title isEqualToString:@"我的位置"]) {
        spotEntityStart.latitude = _autoLocation.location.coordinate.latitude;
        spotEntityStart.longitude = _autoLocation.location.coordinate.longitude;
    }
    start.cityName = [[NSUserDefaults standardUserDefaults] valueForKey:SelectedCityName];
    start.pt = {spotEntityStart.latitude ,spotEntityStart.longitude};
    
   
    DebugLog(@"start: %f, %f", start.pt.latitude, start.pt.longitude);
    BMKPlanNode* end = [[BMKPlanNode alloc]init];
    end.name = spotEntityEnd.title;
    if ([spotEntityEnd.title isEqualToString:@"我的位置"]) {
        spotEntityEnd.latitude = _autoLocation.location.coordinate.latitude;
        spotEntityEnd.longitude = _autoLocation.location.coordinate.longitude;
    }
    end.pt = {spotEntityEnd.latitude, spotEntityEnd.longitude};
    end.cityName = [[NSUserDefaults standardUserDefaults] valueForKey:SelectedCityName];
    
    DebugLog(@"end: %f, %f", end.pt.latitude, end.pt.longitude);
    
    BMKWalkingRoutePlanOption *walkingRouteSearchOption = [[BMKWalkingRoutePlanOption alloc]init];
    walkingRouteSearchOption.from = start;
    walkingRouteSearchOption.to = end;
    BOOL flag = [_routesearch walkingSearch:walkingRouteSearchOption];
    if(flag)
    {
        NSLog(@"walk检索发送成功");
    }
    else
    {
        [super showLoadingView:NO];
        NSLog(@"walk检索发送失败");
    }
}

-(void) onDriveSearch:(NSString *)strRoute
{
//    [super showLoadingView:YES];
//    BMKPlanNode* start = [[BMKPlanNode alloc]init];
//    BMKPlanNode* end = [[BMKPlanNode alloc]init];
    
//    NSMutableArray * array = [[NSMutableArray alloc] init];
    //分割路线
    NSArray *list = [strRoute componentsSeparatedByString:@"|"];
    
//    for (int i = 0; i < [list count]; i++) {
//        NSString *str = [list objectAtIndex:i];
//        NSArray *coordinate = [str componentsSeparatedByString:@","];
//        
//        if (i == 0) {
//            if ([coordinate count] > 1) {
//                NSString *strLat = [coordinate objectAtIndex:1];
//                NSString *strLog = [coordinate objectAtIndex:0];
//                
//                start.cityName = [LocationManagement sharedInstance].city;
//                start.pt = {[strLat doubleValue], [strLog doubleValue]};
//            }
//        }
//        
//        if (i == [list count] -1) {
//            if ([coordinate count] > 1) {
//                NSString *strLat = [coordinate objectAtIndex:1];
//                NSString *strLog = [coordinate objectAtIndex:0];
//                end.cityName = [LocationManagement sharedInstance].city;
//                end.pt = {[strLat doubleValue], [strLog doubleValue]};
//            }
//        }
//        if ([coordinate count] > 1) {
//            NSString *strLat = [coordinate objectAtIndex:1];
//            NSString *strLog = [coordinate objectAtIndex:0];
//            
//            BMKPlanNode* wayPointItem1 = [[BMKPlanNode alloc]init];
//            wayPointItem1.cityName = [[NSUserDefaults standardUserDefaults] valueForKey:@"select_city_name"];
//            wayPointItem1.pt = {[strLat doubleValue], [strLog doubleValue]};
//            wayPointItem1.name = @"";
//            [array addObject:wayPointItem1];
//        }
//    }
//    BMKDrivingRoutePlanOption *drivingRouteSearchOption = [[BMKDrivingRoutePlanOption alloc]init];
//    drivingRouteSearchOption.from = start;
//    drivingRouteSearchOption.to = end;
//    drivingRouteSearchOption.wayPointsArray = array;
//    BOOL flag = [_routesearch drivingSearch:drivingRouteSearchOption];
//    
//    if(flag)
//    {
//        NSLog(@"search success.");
//    }
//    else
//    {
//        NSLog(@"search failed!");
//        [super showLoadingView:NO];
//    }
    [self.locationArrayM removeAllObjects];
    for (int i = 0 ; i < [list count]; i++)
    {
        NSString *str = [list objectAtIndex:i];
        NSArray *coordinate = [str componentsSeparatedByString:@","];
        CLLocation *location = [[CLLocation alloc]initWithLatitude:[[coordinate lastObject] doubleValue] longitude:[[coordinate firstObject] doubleValue]];
        [self.locationArrayM addObject:location];
        //添加annotation节点
//        RouteAnnotation* item = [[RouteAnnotation alloc]init];
//        item.coordinate = location;
//        item.title = transitStep.entraceInstruction;
//        item.degree = transitStep.direction * 30;
//        item.type = 4;
//        [_mapView addAnnotation:item];
//        [self creatRouteAnnotationWithLocaiton:location title:@""];
    }
    
    
    [self drawWalkPolyline];
}


//根据polyline设置地图范围
- (void)mapViewFitPolyLine:(BMKPolyline *) polyLine {
    CGFloat ltX, ltY, rbX, rbY;
    if (polyLine.pointCount < 1) {
        return;
    }
    BMKMapPoint pt = polyLine.points[0];
    ltX = pt.x, ltY = pt.y;
    rbX = pt.x, rbY = pt.y;
    for (int i = 1; i < polyLine.pointCount; i++) {
        BMKMapPoint pt = polyLine.points[i];
        if (pt.x < ltX) {
            ltX = pt.x;
        }
        if (pt.x > rbX) {
            rbX = pt.x;
        }
        if (pt.y > ltY) {
            ltY = pt.y;
        }
        if (pt.y < rbY) {
            rbY = pt.y;
        }
    }
    BMKMapRect rect;
    rect.origin = BMKMapPointMake(ltX , ltY);
    rect.size = BMKMapSizeMake(rbX - ltX, rbY - ltY);
    [_mapView setVisibleMapRect:rect];
    _mapView.zoomLevel = _mapView.zoomLevel - 0.3;
    _currentZoomLevel = _mapView.zoomLevel;
}



- (IBAction)doBack:(id)sender {

    [_locService stopUserLocationService];

    if (_mapView) {
        _mapView =nil;
    }
    if (![SpotDetailViewController sharedInstance].isPause &&[SpotDetailViewController sharedInstance].isPlay) {
        [JDStatusBarNotification showWithStatus:[NSString stringWithFormat:@"正在播放：%@",musicSpotEntity.title] styleName:SBStyle2];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}
/**
 *  play music local or remote
 *
 *
 */
-(void)autoPlayAudioWithSpotEntity:(SpotEntity *)entity
{
    if (![SpotDetailViewController sharedInstance].isAppear) {
         [JDStatusBarNotification showWithStatus:[NSString stringWithFormat:@"正在播放：%@",musicSpotEntity.title] styleName:SBStyle2];
    }
   
    for (int i = 0; i<[_mapView.annotations count]; i++) {
        if ([[_mapView.annotations objectAtIndex:i] isKindOfClass:[BasicMapAnnotation class]]) {
            BasicMapAnnotation *annotation = [_mapView.annotations objectAtIndex:i];
            BMKAnnotationView *anView=  [_mapView viewForAnnotation:[_mapView.annotations objectAtIndex:i]];
            anView.image = [UIImage imageNamed:@"地图图标_景点"];
            [anView setSelected:NO animated:YES];
            if ([entity.title isEqualToString:annotation.title]) {
                
                [anView setSelected:YES animated:YES];
                anView.image = [UIImage imageNamed:@"自动语音播报"];
            }
        }
      }
        _playView.progressSlider.progress = 0;
        [self performSelector:@selector(showLocationUpWithSpotEntity:) withObject:entity afterDelay:0.0];
        
        oneTime = YES;
//        if ([[NSFileManager defaultManager] fileExistsAtPath:spot_path]) {
//            NSString *localAudioPath = [CommonService addLocalRootPath:[entity audio] ParkId:parkEntity.ID];
//            [self playLocalFile:localAudioPath];
//        } else {
//            [self playRemoteUrl:entity.audio];
//        }
    for (int i = 0; i<[musicArrayList count]; i++) {
        if ([musicArrayList objectAtIndex:i] == entity) {
            __weak __typeof(self)weakSelf  = self;
            
            [SpotDetailViewController sharedInstance].musicArrayNumber = i;
            [SpotDetailViewController sharedInstance].musicArray = musicArrayList;
            [SpotDetailViewController sharedInstance].parkEntity = parkEntity;
            [[SpotDetailViewController sharedInstance] initMainView];
            [[SpotDetailViewController sharedInstance] playMusicProgress:^(double progress) {
                _playView.progressSlider.progress = progress;
            } finshBlock:^{
                _playView.progressSlider.progress = 0;
                DebugLog(@"===========%f",_playView.progressSlider.progress);
               
                _playView.btnPlay.hidden = NO;
                _playView.btnStop.hidden = YES;
                if (autoPlayType == AutoPlayTypeYes) {
                    if (oneTime) {
                        [_arrayMusicNumber removeAllObjects];
                        autoStart = YES;
                        isCircle = YES;
                        [weakSelf didUpdateBMKUserLocation:_autoLocation];
                    }
                }
            }nextBlock:^(SpotEntity *entity){
                _playView.entity = entity;
                _playView.btnPlay.hidden = YES;
                _playView.btnStop.hidden = NO;
                for (int i = 0; i<[_mapView.annotations count]; i++) {
                    if ([[_mapView.annotations objectAtIndex:i] isKindOfClass:[BasicMapAnnotation class]]) {
                        BasicMapAnnotation *annotation = [_mapView.annotations objectAtIndex:i];
                        BMKAnnotationView *anView=  [_mapView viewForAnnotation:[_mapView.annotations objectAtIndex:i]];
                        anView.image = [UIImage imageNamed:@"地图图标_景点"];
                        [anView setSelected:NO animated:YES];
                        if ([_playView.entity.title isEqualToString:annotation.title]) {
                                      
                            [anView setSelected:YES animated:YES];
                            anView.image = [UIImage imageNamed:@"自动语音播报"];
                        }
                    }
                }

            }];
          
            break;
        }
    }

}


-(void)playRemoteUrl:(NSString *)mp3Path {
     __weak __typeof(self)weakSelf  = self;
//    [[SpotDetailViewController sharedInstance] stopAudio];
    [[AFSoundManager sharedManager] startStreamingRemoteAudioFromURL:mp3Path andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (elapsedTime == 0 && timeRemaining ==0 ) {
            }else{
                _playView.progressSlider.progress = elapsedTime/(timeRemaining+elapsedTime);
               
                if(_playView.progressSlider.progress == 1){
                     [weakSelf stopAudio] ;
                    _playView.progressSlider.progress = 0;
                     DebugLog(@"===========%f",_playView.progressSlider.progress);
                    
                    _playView.btnPlay.hidden = NO;
                    _playView.btnStop.hidden = YES;
                    if (autoPlayType == AutoPlayTypeYes) {
                        if (oneTime) {
                            [_arrayMusicNumber removeAllObjects];
                            autoStart = YES;
                            isCircle = YES;
                            [weakSelf didUpdateBMKUserLocation:_autoLocation];
                        }
                    }
                   
                }
            }
            
        });
        
        
    }];
    
}
-(void)playLocalFile:(NSString *)mp3Path
{
    __weak __typeof(self)weakSelf  = self;
//    [JDStatusBarNotification dismiss];
  
    _playView.progressSlider.progress = 0;
    [[SpotDetailViewController sharedInstance] stopAudio];
    [[AFSoundManager sharedManager] startPlayingLocalFileWithName:mp3Path andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (elapsedTime == 0 && timeRemaining ==0 ) {
            }else{
                _playView.progressSlider.progress = elapsedTime/(timeRemaining+elapsedTime);
                
                if(_playView.progressSlider.progress == 1){
                    [weakSelf stopAudio] ;
                       _playView.progressSlider.progress = 0;
                    DebugLog(@"===========%f",_playView.progressSlider.progress);
                    reStart = YES;
                    _playView.btnPlay.hidden = NO;
                    _playView.btnStop.hidden = YES;
                    if (autoPlayType == AutoPlayTypeYes) {
                        if (oneTime) {
                            [_arrayMusicNumber removeAllObjects];
                            autoStart = YES;
                            isCircle = YES;
                            [weakSelf didUpdateBMKUserLocation:_autoLocation];
                        }
                    }

                    
                }
            }
            
        });
        
    }];
    
}
- (IBAction)closeAutoPlay:(id)sender {
    
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        ALERT_ERR_MSG(LocationOpenTip);
    }else{
        if (!autoStart) {

            CLLocation *origin = [[CLLocation alloc] initWithLatitude:_autoLocation.location.coordinate.latitude longitude:_autoLocation.location.coordinate.longitude] ;
            CLLocation *final = [[CLLocation alloc] initWithLatitude:[parkEntity.latitude doubleValue] longitude:[parkEntity.longitude doubleValue]];
            CLLocationDistance distance = [origin distanceFromLocation:final];
            if (distance <[parkEntity.radius doubleValue]){
                autoStart = YES;
                isCircle = YES;
             
                autoPlayType = AutoPlayTypeYes;
                [SpotDetailViewController sharedInstance].autoPlayFunction = YES;
                [SVProgressHUD showSuccessWithStatus:@"自动语音讲解功能开启"];
                [btnCancleAuto setBackgroundImage:[UIImage imageNamed:@"取消auto讲解.png"] forState:UIControlStateNormal];
                [self didUpdateBMKUserLocation:_autoLocation];
            }else{
            
                //弹出提示框
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前位置不在景区范围内" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alert show];
                
            }
        
        }else{
              [btnCancleAuto setBackgroundImage:[UIImage imageNamed:@"auto讲解.png"] forState:UIControlStateNormal];
           
            [self doClose:nil];
        }
    }
    
        
}
-(void)timerFired
{
    [_myTimer invalidate];
    [_locService startUserLocationService];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 2222) {
        musicSpotEntity = [_arrayMusicNumber objectAtIndex:buttonIndex];

        [self autoPlayAudioWithSpotEntity:musicSpotEntity];
        
    }
    if (alertView.tag == 3333) {
        if ( alertView.cancelButtonIndex == buttonIndex) {
            _block(NO);
            [alertView removeFromSuperview ];
        }else{
            if (autoPlayType == AutoPlayTypeYes||autoStart==NO) {
                isCircle = NO;
                
                [btnCancleAuto setBackgroundImage:[UIImage imageNamed:@"auto讲解.png"] forState:UIControlStateNormal];
                [SVProgressHUD showErrorWithStatus:@"自动语音讲解功能关闭"];
                [sameArray removeAllObjects];
                autoPlayType = AutoPlayTypeNo;
                autoStart = NO;
                 [_arrayMusicNumber removeAllObjects];
                [SpotDetailViewController sharedInstance].autoPlayFunction = NO;
            }
//            [self doClose:nil];
            _block(YES);
            
        }
    }
    if (alertView.tag == 10001)
    {
        if (buttonIndex == 1) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        }
    }
}
-(void)showLocationUpWithSpotEntity:(SpotEntity *)entity
{
    _viewPop.hidden = YES;
    _labelLine.hidden = YES;
    _businessView.hidden = YES;
    viewTogether.hidden = YES;
     isPlay = YES;
    if (![self.view.subviews containsObject:_playView]) {
        [self.view addSubview:_playView];
        _playView.frame = CGRectMake(8, SCREEN_HEIGHT , SCREEN_WIDTH -16, (SCREEN_WIDTH - 16)*117/362);
        [UIView animateWithDuration:0.3 animations:^{
            _playView.layer.transform = CATransform3DMakeTranslation(0,-(SCREEN_WIDTH - 16)*117/362-5, 0);
        }];
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            _playView.layer.transform = CATransform3DMakeTranslation(0,-(SCREEN_WIDTH - 16)*117/362-5, 0);
        }];
    }
     _playView.parkEntity = parkEntity;
    _playView.entity = entity;
    _textViewContent.layoutManager.allowsNonContiguousLayout = NO;
    _textViewContent.text = entity.content;

    _height3.constant = _playView.bounds.size.height-40 ;
    [UIView animateWithDuration:0.3 animations:^{
        [self.view layoutIfNeeded];
    }];
    _playView.btnPlay.hidden = YES;
    _playView.btnStop.hidden = NO;

}
-(void)hideLocationUp
{
    [SpotDetailViewController sharedInstance].isPlay = NO;
    for (int i = 0; i<[_mapView.annotations count]; i++) {
        if ([[_mapView.annotations objectAtIndex:i] isKindOfClass:[BasicMapAnnotation class]]) {
        BasicMapAnnotation *annotation = [_mapView.annotations objectAtIndex:i];
        BMKAnnotationView *anView=  [_mapView viewForAnnotation:annotation];
        anView.image = [UIImage imageNamed:@"地图图标_景点"];
        [anView setSelected:NO animated:YES];
        }
    }
    [UIView animateWithDuration:0.3 animations:^{
        _viewExplain.layer.transform = CATransform3DIdentity;
        btnLocation.layer.transform = CATransform3DIdentity;
        btnSmall.layer.transform =CATransform3DIdentity;
        btnBig.layer.transform = CATransform3DIdentity;
        btnCancleAuto.layer.transform = CATransform3DIdentity;
        _playView.layer.transform = CATransform3DIdentity;
//        _mapView.layer.transform = CATransform3DIdentity;
       
        _viewExplain.hidden = YES;
//        viewAutoPlay.frame = CGRectMake(8, SCREEN_HEIGHT, SCREEN_WIDTH -16, (SCREEN_WIDTH - 16)*117/362);
        _height3.constant = 30;
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            _playView.progressSlider.progress = 0;
            viewTogether.hidden = NO;
            _labelLine.hidden = NO;
             [_mapView setMapCenterToScreenPt:CGPointMake(self.view.center.x, self.view.center.y )];
        }];
        
    }];

}


//- (IBAction)btnStop:(id)sender {
//    _playView.btnStop.hidden = YES;
//    _playView.btnPlay.hidden = NO;
//    isPause = NO;
//    if (reStart) {
//        _playView.progressSlider.progress = 0;
//        reStart = NO;
//        [self autoPlayAudioWithSpotEntity:musicSpotEntity];
//    }else{
//        [self resumeAudio];
//    }
//}

//- (IBAction)play:(id)sender {
//    _playView.btnStop.hidden = NO;
//    _playView.btnPlay.hidden = YES;
//    isPause = YES;
//    [self pauseAudio];
//}
-(void)pauseAudio {
    [[SpotDetailViewController sharedInstance] pauseMusic];
    DebugLog(@"========pause");
//    [JDStatusBarNotification dismissAnimated:YES];
}
-(void)restartAudio{
//    [JDStatusBarNotification showWithStatus:[NSString stringWithFormat:@"正在播放：%@",musicSpotEntity.title] styleName:SBStyle2];

    [[SpotDetailViewController sharedInstance] updatePlayerSetting];
}
-(void)resumeAudio {
//    [JDStatusBarNotification showWithStatus:[NSString stringWithFormat:@"正在播放：%@",musicSpotEntity.title] styleName:SBStyle2];
    [[SpotDetailViewController sharedInstance]  playMusic];
}
-(void)stopAudio
{
    [_arrayMusicNumber removeAllObjects];
//    [JDStatusBarNotification dismissAnimated:YES];
     [[SpotDetailViewController sharedInstance] stopAudio];
}

-(void)gxScrollView:(GXScrollView *)scrollView ActionWithIndex:(NSInteger)tag
{
    if (scrollView.tag == 2000) {
        switch (tag) {
            case 21:
                [self doMapAnnoationActionWithString:@"2.1"];
                break;
            case 22:
                [self doMapAnnoationActionWithString:@"2.2"];
                break;
            case 23:
                [self doMapAnnoationActionWithString:@"2.3"];
            break;
            case 24:
                [self doMapAnnoationActionWithString:@"2.4"];
            break;
            case 25:
                [self doMapAnnoationActionWithString:@"2.5"];
            break;
        }
    }
    if (scrollView.tag == 4000) {
        switch (tag) {
            case 4:
                [self doRouteAction];
                break;
            case 5:
                [self doHospitalAction];
                break;
            case 6:
                [self doEnterAction];
                break;
            case 7:
                [self doRestAction];
                break;
            case 8:
                [self doParkCarAction];
                break;
            case 9:
                [self doSellTicketAction];
                break;
            case 10:
                [self doMapAnnoationActionWithString:@"10"];
                break;
            case 11:
                [self doMapAnnoationActionWithString:@"11"];
                break;
            case 12:
                [self doMapAnnoationActionWithString:@"12"];
                break;
            case 13:
                [self doMapAnnoationActionWithString:@"13"];
                break;
            case 14:
                [self doMapAnnoationActionWithString:@"14"];
                break;
            case 15:
                [self doMapAnnoationActionWithString:@"15"];
                break;
        }
    }
}


- (void)drawWalkPolyline
{
    //轨迹点
    NSUInteger count = self.locationArrayM.count;
    
    // 手动分配存储空间，结构体：地理坐标点，用直角地理坐标表示 X：横坐标 Y：纵坐标
    BMKMapPoint *tempPoints = new BMKMapPoint[count];
    
    [self.locationArrayM enumerateObjectsUsingBlock:^(CLLocation *location, NSUInteger idx, BOOL *stop) {
        BMKMapPoint locationPoint = BMKMapPointForCoordinate(location.coordinate);
        tempPoints[idx] = locationPoint;
//        NSLog(@"idx = %ld,tempPoints X = %f Y = %f",idx,tempPoints[idx].x,tempPoints[idx].y);
        
        // 放置起点旗帜
        if (0 == idx && TrailStart == self.trail && self.startPoint == nil) {
            self.startPoint = [self creatPointWithLocaiton:location title:@"起点"];
        }
    }];
    
    //移除原有的绘图
    if (self.polyLine) {
        [_mapView removeOverlay:self.polyLine];
    }
    
    // 通过points构建BMKPolyline
    self.polyLine = [BMKPolyline polylineWithPoints:tempPoints count:count];
    
    //添加路线,绘图
    if (self.polyLine) {
        [_mapView addOverlay:self.polyLine];
    }
    
    // 清空 tempPoints 内存
    delete []tempPoints;
    
    [self mapViewFitPolyLine:self.polyLine];
    [super showLoadingView:NO];
}



- (BMKPointAnnotation *)creatPointWithLocaiton:(CLLocation *)location title:(NSString *)title;
{
    BMKPointAnnotation *point = [[BMKPointAnnotation alloc] init];
    point.coordinate = location.coordinate;
    point.title = title;
    [_mapView addAnnotation:point];
    
    return point;
}

- (RouteAnnotation *)creatRouteAnnotationWithLocaiton:(CLLocation *)location title:(NSString *)title;
{
    RouteAnnotation *point = [[RouteAnnotation alloc] init];
    point.coordinate = location.coordinate;
    point.type = 3;
    point.title = title;
    [_mapView addAnnotation:point];
    return point;
}

- (NSMutableArray *)locationArrayM
{
    if (_locationArrayM == nil) {
        _locationArrayM = [NSMutableArray array];
    }
    
    return _locationArrayM;
}


- (void)clean
{
    
    //清空数组
    [self.locationArrayM removeAllObjects];
    
    //清屏，移除标注点
    if (self.startPoint) {
        [_mapView removeAnnotation:self.startPoint];
        self.startPoint = nil;
    }
    if (self.endPoint) {
        [_mapView removeAnnotation:self.endPoint];
        self.endPoint = nil;
    }
    if (self.polyLine) {
        [_mapView removeOverlay:self.polyLine];
        self.polyLine = nil;
    }
}
-(void)doChange
{
    
    CLLocation *origin = [[CLLocation alloc] initWithLatitude:_autoLocation.location.coordinate.latitude longitude:_autoLocation.location.coordinate.longitude] ;
    CLLocation *final = [[CLLocation alloc] initWithLatitude:[parkEntity.latitude doubleValue] longitude:[parkEntity.longitude doubleValue]];
    CLLocationDistance distance = [origin distanceFromLocation:final];
    if (distance < [parkEntity.radius doubleValue]){
        [btnCancleAuto setBackgroundImage:[UIImage imageNamed:@"取消auto讲解.png"] forState:UIControlStateNormal];
        autoPlayType = AutoPlayTypeYes;
        [SpotDetailViewController sharedInstance].autoPlayFunction = YES;
        autoStart = YES;
        isCircle = YES;
        [SVProgressHUD showSuccessWithStatus:@"自动语音讲解功能开启"];

        [self didUpdateBMKUserLocation:_autoLocation];
    }else{
        autoPlayType = AutoPlayTypeNo;
        [SpotDetailViewController sharedInstance].autoPlayFunction = NO;
    }
    
}
- (IBAction)doClose:(id)sender {
    
    [SpotDetailViewController sharedInstance].isPlay = NO;
    [sameArray removeAllObjects];
    if (autoPlayType == AutoPlayTypeYes||autoStart==NO) {
       isCircle = NO;
        
         [btnCancleAuto setBackgroundImage:[UIImage imageNamed:@"auto讲解.png"] forState:UIControlStateNormal];
        [SVProgressHUD showErrorWithStatus:@"自动语音讲解功能关闭"];
        autoPlayType = AutoPlayTypeNo;
        [SpotDetailViewController sharedInstance].autoPlayFunction = NO;
    }
    [self pauseAudio];
    [self hideLocationUp];
    autoStart = NO;
}
- (IBAction)shareLocationFunction:(id)sender {
    UserEntity *userEntity = [UserEntity sharedInstance];
    if (userEntity.login == NO) {
        LoginViewController *vc = [[LoginViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];

        return;
    }
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        ALERT_ERR_MSG(LocationOpenTip);
        return;
    }
    ShareChooseViewController *vc =[[ShareChooseViewController alloc] init];
    vc.currentLatutide =_autoLocation.location.coordinate.latitude;
    vc.currentLontitude = _autoLocation.location.coordinate.longitude;
    vc.userId = userEntity.userId;
//    vc.userId = @"1";
    vc.userLocation = _autoLocation.location;
    [self.navigationController pushViewController:vc animated:YES];
}

@end





